// 
// HOT4DNN - http://www.HOT4DNN.com
// Copyright (c) 2011
// by Dynamic Generation Inc.
//
// PLEASE REMOVE THIS COPYRIGHT AND PERMISSION NOTICE!
//
// This code template is provided free of charge by Dynamic Generation and HOT4DNN to aid you in developing
// your DotNetNuke(R) Extensions. No warranties are associated with this template, as it is assumed that you,
// the developer, will be providing significant edits to this code as part of your development.
// 
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 
// documentation files (the "Software"), to deal in the Software without restriction, including without limitation 
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and 
// to permit persons to whom the Software is furnished to do so, subject to the following conditions:
// 
// The above copyright notice and this permission notice shall be included in all copies or substantial portions 
// of the Software.
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 
// TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 
// CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
// DEALINGS IN THE SOFTWARE.


using System;
using System.Collections.Generic;
using DotNetNuke.Entities.Modules;
using DotNetNuke.Services.Localization;
using DotNetNuke.Security.Roles;
using System.Web.UI.WebControls;

namespace HOT4DNN.Modules.HelloUser
{
    partial class ViewHelloUser : PortalModuleBase
    {
        protected void Page_Load(System.Object sender, System.EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                AboutUser.Text = Localization.GetString("AboutUser", LocalResourceFile);
                string greetUser;
                if (Request.IsAuthenticated)
                {
                    // Use the Greeting text
                    greetUser = Localization.GetString("Greeting", LocalResourceFile);
                    greetUser = string.Format(greetUser, UserInfo.DisplayName);
                    // List the user's security roles
                    RoleController rl = new RoleController();
                    string[] roleNames = rl.GetRolesByUser(UserId, PortalId);
                    
                    ActiveRoleList.DataSource = roleNames;
                    ActiveRoleList.DataBind();
                    Literal noData = ActiveRoleList.Controls[0].FindControl("NoData") as Literal;
                    if (noData != null)
                        noData.Text = Localization.GetString("NoSecurityRoles", LocalResourceFile);
                }
                else
                {
                    // Only show a general greeting to the anonymous user
                    greetUser = Localization.GetString("AnonymousUser", LocalResourceFile);
                    AboutUser.Visible = false;
                    ActiveRoleList.Visible = false;
                }

                Greeting.Text = greetUser;
            }
        }
    }

}

